﻿using System;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;

namespace RenderHeads.Media.AVProVideo
{
	// Token: 0x0200002D RID: 45
	[HelpURL("http://renderheads.com/product/avpro-video/")]
	[AddComponentMenu("AVPro Video/Subtitles uGUI", 201)]
	public class SubtitlesUGUI : MonoBehaviour
	{
		// Token: 0x0600012A RID: 298 RVA: 0x0000A21C File Offset: 0x0000841C
		private void Start()
		{
			this.ChangeMediaPlayer(this._mediaPlayer);
		}

		// Token: 0x0600012B RID: 299 RVA: 0x0000A22C File Offset: 0x0000842C
		private void OnDestroy()
		{
			this.ChangeMediaPlayer(null);
		}

		// Token: 0x0600012C RID: 300 RVA: 0x0000A238 File Offset: 0x00008438
		public void ChangeMediaPlayer(MediaPlayer newPlayer)
		{
			if (this._mediaPlayer != null)
			{
				this._mediaPlayer.Events.RemoveListener(new UnityAction<MediaPlayer, MediaPlayerEvent.EventType, ErrorCode>(this.OnMediaPlayerEvent));
				this._mediaPlayer = null;
			}
			this._mediaPlayer = newPlayer;
			if (this._mediaPlayer != null)
			{
				this._mediaPlayer.Events.AddListener(new UnityAction<MediaPlayer, MediaPlayerEvent.EventType, ErrorCode>(this.OnMediaPlayerEvent));
			}
		}

		// Token: 0x0600012D RID: 301 RVA: 0x0000A2B0 File Offset: 0x000084B0
		private void OnMediaPlayerEvent(MediaPlayer mp, MediaPlayerEvent.EventType et, ErrorCode errorCode)
		{
			if (et == MediaPlayerEvent.EventType.SubtitleChange)
			{
				string text = this._mediaPlayer.Subtitles.GetSubtitleText();
				text = text.Replace("<font color=", "<color=");
				text = text.Replace("</font>", "</color>");
				text = text.Replace("<u>", string.Empty);
				text = text.Replace("</u>", string.Empty);
				this._text.text = text;
			}
		}

		// Token: 0x04000137 RID: 311
		[SerializeField]
		private MediaPlayer _mediaPlayer;

		// Token: 0x04000138 RID: 312
		[SerializeField]
		private Text _text;
	}
}
